package com.shen.cloud.service;

import com.shen.cloud.pojo.Department;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 降级
 */
@Component
public class DeptClientServiceFallbackFactory implements FallbackFactory {
    /**
     * 不连数据库查数据
     * 与之前熔断不同的是熔断针对的是单个的方法，而降级正对的是整个服务
     * 不要返回一个null 最好返回一个对象
     * @param throwable
     * @return
     */
    public DepartmentClientService create(Throwable throwable) {

        return new DepartmentClientService() {
            public boolean insertDepartment(Department department) {
                return false;
            }

            public Department selectDepartmentById(Long id) {
                return new Department()
                        .setId(id)
                        .setName("id===>"+id+",不存在该用户，或者信息无法找到~")
                        .setDbSource("no database in mysql");
            }

            public List<Department> selectAllDepartment() {
                return null;
            }
        };
    }
}
